﻿using System;

namespace jQueryLib
{
    public interface Promise
    {
        /// <summary>
        /// Add handler to be called when the Deferred object is either resolved or rejected.
        /// </summary>
        /// <param name="del"></param>
        /// <returns></returns>
        Promise Always(Delegate del);

        /// <summary>
        /// Add handlers to be called when the Deferred object is either resolved or rejected.
        /// </summary>
        /// <param name="dels"></param>
        /// <returns></returns>
        Promise Always(params Delegate[] dels);

        /// <summary>
        /// Add handler to be called when the Deferred object is resolved.
        /// </summary>
        /// <param name="del"></param>
        /// <returns></returns>
        Promise Done(Delegate del);

        /// <summary>
        /// Add handlers to be called when the Deferred object is resolved.
        /// </summary>
        /// <param name="dels"></param>
        /// <returns></returns>
        Promise Done(params Delegate[] dels);

        /// <summary>
        /// Add handler to be called when the Deferred object is rejected.
        /// </summary>
        /// <param name="del"></param>
        /// <returns></returns>
        Promise Fail(Delegate del);

        /// <summary>
        /// Add handlers to be called when the Deferred object is rejected.
        /// </summary>
        /// <param name="del"></param>
        /// <returns></returns>
        Promise Fail(params Delegate[] del);

        /// <summary>
        /// Determine the current state of a Deferred object.
        /// </summary>
        /// <returns>
        /// <para>"pending": The Deferred object is not yet in a completed state (neither "rejected" nor "resolved").</para>
        /// <para>"resolved": The Deferred object is in the resolved state, meaning that either deferred.resolve() or deferred.resolveWith() has been called for the object and the doneCallbacks have been called (or are in the process of being called).</para>
        /// <para>"rejected": The Deferred object is in the rejected state, meaning that either deferred.reject() or deferred.rejectWith() has been called for the object and the failCallbacks have been called (or are in the process of being called).</para>
        /// </returns>
        string State();

        /// <summary>
        /// Add handler to be called when the Deferred object is resolved or rejected.
        /// </summary>
        /// <param name="done">A function, called when the Deferred is resolved.</param>
        /// <param name="fail">A function, called when the Deferred is rejected.</param>
        /// <returns></returns>
        Promise Then(Delegate done, Delegate fail);

        /// <summary>
        /// Add handlers to be called when the Deferred object is resolved or rejected.
        /// </summary>
        /// <param name="done">Array of functions, called when the Deferred is resolved.</param>
        /// <param name="fail">Array of functions, called when the Deferred is rejected.</param>
        /// <returns></returns>
        Promise Then(Delegate[] done, Delegate[] fail);

        /// <summary>
        /// Add handler to be called when the Deferred object is resolved or rejected.
        /// </summary>
        /// <param name="done">A function, called when the Deferred is resolved.</param>
        /// <param name="fail">A function, called when the Deferred is rejected.</param>
        /// <param name="progress">A function, called when the Deferred notifies progress.</param>
        /// <returns></returns>
        Promise Then(Delegate done, Delegate fail, Delegate progress);

        /// <summary>
        /// Add handlers to be called when the Deferred object is resolved or rejected.
        /// </summary>
        /// <param name="done">Array of functions, called when the Deferred is resolved.</param>
        /// <param name="fail">Array of functions, called when the Deferred is rejected.</param>
        /// <param name="progress">Array of functions, called when the Deferred notifies progress.</param>
        /// <returns></returns>
        Promise Then(Delegate[] done, Delegate[] fail, Delegate[] progress);

        /// <summary>
        /// Add handler to be called when the Deferred object generates progress notifications.
        /// </summary>
        /// <param name="del"> A function that is called when the Deferred generates progress notifications.</param>
        /// <returns></returns>
        Promise Progress(Delegate del);

        /// <summary>
        /// Add handlers to be called when the Deferred object generates progress notifications.
        /// </summary>
        /// <param name="del"> Array of functions that is called when the Deferred generates progress notifications.</param>
        /// <returns></returns>
        Promise Progress(Delegate[] del);
    }
}
